#include <net/if.h>
#include <string.h>
#include <sys/stat.h>
-#include <syslog.h>
#include <uci.h>
#include <uci_blob.h>
/* IAID = uint32, RFC8415, §21.4, §21.5, §21.21 */
if (iaid_str_len < 1 || iaid_str_len > 2 * sizeof(uint32_t)) {
- syslog(LOG_ERR, "Invalid IAID length '%s'", iaid_str);
+ error("Invalid IAID length '%s'", iaid_str);
return false;
}
errno = 0;
duid->iaid = strtoul(iaid_str, &end, 16);
if (errno || *end != '\0') {
- syslog(LOG_ERR, "Invalid IAID '%s'", iaid_str);
+ error("Invalid IAID '%s'", iaid_str);
return false;
}
}
if (duid_str_len < 2 || duid_str_len > DUID_MAX_LEN * 2 || duid_str_len % 2) {
- syslog(LOG_ERR, "Invalid DUID length '%.*s'", (int)duid_str_len, duid_str);
+ error("Invalid DUID length '%.*s'", (int)duid_str_len, duid_str);
return false;
}
duid_len = odhcpd_unhexlify(duid->id, duid_str_len / 2, duid_str);
if (duid_len < 0) {
- syslog(LOG_ERR, "Invalid DUID '%.*s'", (int)duid_str_len, duid_str);
+ error("Invalid DUID '%.*s'", (int)duid_str_len, duid_str);
return false;
}
if (!priority) {
goto err;
} else if (sscanf(priority, "%" SCNu16, &dnr.priority) != 1) {
- syslog(LOG_ERR, "Unable to parse priority '%s'", priority);
+ error("Unable to parse priority '%s'", priority);
goto err;
} else if (dnr.priority == 0) {
- syslog(LOG_ERR, "Invalid priority '%s'", priority);
+ error("Invalid priority '%s'", priority);
goto err;
}
adn[adn_len - 1] = '\0';
if (adn_len >= sizeof(adn_buf)) {
- syslog(LOG_ERR, "Hostname '%s' too long", adn);
+ error("Hostname '%s' too long", adn);
goto err;
}
adn_len = dn_comp(adn, adn_buf, sizeof(adn_buf), NULL, NULL);
if (adn_len <= 0) {
- syslog(LOG_ERR, "Unable to parse hostname '%s'", adn);
+ error("Unable to parse hostname '%s'", adn);
goto err;
}
dnr.addr4_cnt++;
} else {
- syslog(LOG_ERR, "Unable to parse IP address '%s'", addr);
+ error("Unable to parse IP address '%s'", addr);
goto err;
}
}
uint32_t lifetime;
if (!svc_val || sscanf(svc_val, "%" SCNu32, &lifetime) != 1) {
- syslog(LOG_ERR, "Invalid value '%s' for _lifetime", svc_val ? svc_val : "");
+ error("Invalid value '%s' for _lifetime", svc_val ? svc_val : "");
goto err;
}
break;
if (svc_id >= DNR_SVC_MAX) {
- syslog(LOG_ERR, "Invalid SvcParam '%s'", svc_key);
+ error("Invalid SvcParam '%s'", svc_key);
goto err;
}
break;
if (mkey >= DNR_SVC_MAX || !svc_vals[mkey]) {
- syslog(LOG_ERR, "Invalid value '%s' for SvcParam 'mandatory'", mkey_str);
+ error("Invalid value '%s' for SvcParam 'mandatory'", mkey_str);
goto err;
}
alpn_id_len = strlen(alpn_id_str);
if (alpn_id_len > UINT8_MAX) {
- syslog(LOG_ERR, "Invalid value '%s' for SvcParam 'alpn'", alpn_id_str);
+ error("Invalid value '%s' for SvcParam 'alpn'", alpn_id_str);
goto err;
}
uint16_t port;
if (sscanf(svc_val_str, "%" SCNu16, &port) != 1) {
- syslog(LOG_ERR, "Invalid value '%s' for SvcParam 'port'", svc_val_str);
+ error("Invalid value '%s' for SvcParam 'port'", svc_val_str);
goto err;
}
case DNR_SVC_OHTTP:
if (strlen(svc_val_str) > 0) {
- syslog(LOG_ERR, "Invalid value '%s' for SvcParam 'port'", svc_val_str);
+ error("Invalid value '%s' for SvcParam 'port'", svc_val_str);
goto err;
}
/* fall through */
break;
case DNR_SVC_ECH:
- syslog(LOG_ERR, "SvcParam 'ech' is not implemented");
+ error("SvcParam 'ech' is not implemented");
goto err;
case DNR_SVC_IPV4HINT:
/* fall through */
case DNR_SVC_IPV6HINT:
- syslog(LOG_ERR, "SvcParam '%s' is not allowed", svc_param_key_names[svc_key]);
+ error("SvcParam '%s' is not allowed", svc_param_key_names[svc_key]);
goto err;
}
}
if (time > 0)
iface->dhcp_leasetime = time;
else
- syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
- iface_attrs[IFACE_ATTR_LEASETIME].name, iface->name);
+ error("Invalid %s value configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_LEASETIME].name, iface->name);
}
if (time > 0)
iface->max_preferred_lifetime = time;
else
- syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
- iface_attrs[IFACE_ATTR_MAX_PREFERRED_LIFETIME].name, iface->name);
-
+ error("Invalid %s value configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_MAX_PREFERRED_LIFETIME].name, iface->name);
}
if ((c = tb[IFACE_ATTR_MAX_VALID_LIFETIME])) {
if (time > 0)
iface->max_valid_lifetime = time;
else
- syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
- iface_attrs[IFACE_ATTR_MAX_VALID_LIFETIME].name, iface->name);
-
+ error("Invalid %s value configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_MAX_VALID_LIFETIME].name, iface->name);
}
if ((c = tb[IFACE_ATTR_START])) {
if (iface->ra != MODE_DISABLED)
iface->ignore = false;
} else
- syslog(LOG_ERR, "Invalid %s mode configured for interface '%s'",
- iface_attrs[IFACE_ATTR_RA].name, iface->name);
+ error("Invalid %s mode configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_RA].name, iface->name);
}
if ((c = tb[IFACE_ATTR_DHCPV4])) {
iface->ignore = false;
}
} else
- syslog(LOG_ERR, "Invalid %s mode configured for interface %s",
- iface_attrs[IFACE_ATTR_DHCPV4].name, iface->name);
+ error("Invalid %s mode configured for interface %s",
+ iface_attrs[IFACE_ATTR_DHCPV4].name, iface->name);
}
if ((c = tb[IFACE_ATTR_DHCPV6])) {
if (iface->dhcpv6 != MODE_DISABLED)
iface->ignore = false;
} else
- syslog(LOG_ERR, "Invalid %s mode configured for interface '%s'",
- iface_attrs[IFACE_ATTR_DHCPV6].name, iface->name);
+ error("Invalid %s mode configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_DHCPV6].name, iface->name);
}
if ((c = tb[IFACE_ATTR_NDP])) {
if (iface->ndp != MODE_DISABLED)
iface->ignore = false;
} else
- syslog(LOG_ERR, "Invalid %s mode configured for interface '%s'",
- iface_attrs[IFACE_ATTR_NDP].name, iface->name);
+ error("Invalid %s mode configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_NDP].name, iface->name);
}
if ((c = tb[IFACE_ATTR_ROUTER])) {
iface->dhcpv4_router[iface->dhcpv4_router_cnt - 1] = addr4;
} else
- syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
- iface_attrs[IFACE_ATTR_ROUTER].name, iface->name);
+ error("Invalid %s value configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_ROUTER].name, iface->name);
}
}
if (inet_pton(AF_INET, blobmsg_get_string(cur), &addr4) == 1) {
if (addr4.s_addr == INADDR_ANY) {
- syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
- iface_attrs[IFACE_ATTR_DNS].name, iface->name);
-
+ error("Invalid %s value configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_DNS].name, iface->name);
continue;
}
iface->dhcpv4_dns[iface->dhcpv4_dns_cnt - 1] = addr4;
} else if (inet_pton(AF_INET6, blobmsg_get_string(cur), &addr6) == 1) {
if (IN6_IS_ADDR_UNSPECIFIED(&addr6)) {
- syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
- iface_attrs[IFACE_ATTR_DNS].name, iface->name);
-
+ error("Invalid %s value configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_DNS].name, iface->name);
continue;
}
iface->dns[iface->dns_cnt - 1] = addr6;
} else
- syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
- iface_attrs[IFACE_ATTR_DNS].name, iface->name);
+ error("Invalid %s value configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_DNS].name, iface->name);
}
}
len = dn_comp(domain, buf, sizeof(buf), NULL, NULL);
if (len <= 0) {
- syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
- iface_attrs[IFACE_ATTR_DOMAIN].name, iface->name);
-
+ error("Invalid %s value configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_DOMAIN].name, iface->name);
continue;
}
iface->dhcpv6_pd_min_len = PD_MIN_LEN_MAX;
iface->dhcpv6_pd_min_len = pd_min_len;
if (pd_min_len >= PD_MIN_LEN_MAX)
- syslog(LOG_WARNING, "Clamped invalid %s value configured for interface '%s' to %d",
- iface_attrs[IFACE_ATTR_DHCPV6_PD_MIN_LEN].name, iface->name, iface->dhcpv6_pd_min_len);
+ warn("Clamped invalid %s value configured for interface '%s' to %d",
+ iface_attrs[IFACE_ATTR_DHCPV6_PD_MIN_LEN].name, iface->name, iface->dhcpv6_pd_min_len);
}
if ((c = tb[IFACE_ATTR_DHCPV6_NA]))
iface->dhcpv6_hostid_len = hostid_len;
if (original_hostid_len != hostid_len) {
- syslog(LOG_WARNING, "Clamped invalid %s value configured for interface '%s' to %d",
- iface_attrs[IFACE_ATTR_DHCPV6_HOSTID_LEN].name, iface->name, iface->dhcpv6_hostid_len);
+ warn("Clamped invalid %s value configured for interface '%s' to %d",
+ iface_attrs[IFACE_ATTR_DHCPV6_HOSTID_LEN].name, iface->name, iface->dhcpv6_hostid_len);
}
}
iface->ra_flags = 0;
if (parse_ra_flags(&iface->ra_flags, c) < 0)
- syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
- iface_attrs[IFACE_ATTR_RA_FLAGS].name, iface->name);
+ error("Invalid %s value configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_RA_FLAGS].name, iface->name);
}
if ((c = tb[IFACE_ATTR_RA_REACHABLETIME])) {
*/
iface->ra_reachabletime = ra_reachabletime <= AdvReachableTime ? ra_reachabletime : AdvReachableTime;
if(ra_reachabletime > AdvReachableTime)
- syslog(LOG_WARNING, "Clamped invalid %s value configured for interface '%s' to %d",
- iface_attrs[IFACE_ATTR_RA_REACHABLETIME].name, iface->name, iface->ra_reachabletime);
+ warn("Clamped invalid %s value configured for interface '%s' to %d",
+ iface_attrs[IFACE_ATTR_RA_REACHABLETIME].name, iface->name, iface->ra_reachabletime);
}
if ((c = tb[IFACE_ATTR_RA_RETRANSTIME])) {
iface->ra_retranstime = ra_retranstime <= RETRANS_TIMER_MAX ? ra_retranstime : RETRANS_TIMER_MAX;
if (ra_retranstime > RETRANS_TIMER_MAX)
- syslog(LOG_WARNING, "Clamped invalid %s value configured for interface '%s' to %d",
- iface_attrs[IFACE_ATTR_RA_RETRANSTIME].name, iface->name, iface->ra_retranstime);
+ warn("Clamped invalid %s value configured for interface '%s' to %d",
+ iface_attrs[IFACE_ATTR_RA_RETRANSTIME].name, iface->name, iface->ra_retranstime);
}
if ((c = tb[IFACE_ATTR_RA_HOPLIMIT])) {
/* RFC4861 §6.2.1 : AdvCurHopLimit */
iface->ra_hoplimit = ra_hoplimit <= AdvCurHopLimit ? ra_hoplimit : AdvCurHopLimit;
if(ra_hoplimit > AdvCurHopLimit)
- syslog(LOG_WARNING, "Clamped invalid %s value configured for interface '%s' to %d",
- iface_attrs[IFACE_ATTR_RA_HOPLIMIT].name, iface->name, iface->ra_hoplimit);
+ warn("Clamped invalid %s value configured for interface '%s' to %d",
+ iface_attrs[IFACE_ATTR_RA_HOPLIMIT].name, iface->name, iface->ra_hoplimit);
}
iface->ra_mtu = ra_mtu;
if (original_ra_mtu != ra_mtu) {
- syslog(LOG_WARNING, "Clamped invalid %s value configured for interface '%s' to %d",
- iface_attrs[IFACE_ATTR_RA_MTU].name, iface->name, iface->ra_mtu);
+ warn("Clamped invalid %s value configured for interface '%s' to %d",
+ iface_attrs[IFACE_ATTR_RA_MTU].name, iface->name, iface->ra_mtu);
}
}
continue;
if (parse_dnr_str(blobmsg_get_string(cur), iface))
- syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
- iface_attrs[IFACE_ATTR_DNR].name, iface->name);
+ error("Invalid %s value configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_DNR].name, iface->name);
}
}
iface->pref64_prefix[2] = 0;
break;
default:
- syslog(LOG_WARNING, "Invalid PREF64 prefix size (%d), "
- "ignoring ra_pref64 option!", iface->pref64_length);
+ warn("Invalid PREF64 prefix size (%d), ignoring ra_pref64 option!",
+ iface->pref64_length);
iface->pref64_length = 0;
}
}
else if (!strcmp(prio, "medium") || !strcmp(prio, "default"))
iface->route_preference = 0;
else
- syslog(LOG_ERR, "Invalid %s mode configured for interface '%s'",
- iface_attrs[IFACE_ATTR_RA_PREFERENCE].name, iface->name);
+ error("Invalid %s mode configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_RA_PREFERENCE].name, iface->name);
}
if ((c = tb[IFACE_ATTR_PD_MANAGER]))
if ((c = tb[IFACE_ATTR_PD_CER]) &&
inet_pton(AF_INET6, blobmsg_get_string(c), &iface->dhcpv6_pd_cer) < 1)
- syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
- iface_attrs[IFACE_ATTR_PD_CER].name, iface->name);
+ error("Invalid %s value configured for interface '%s'",
+ iface_attrs[IFACE_ATTR_PD_CER].name, iface->name);
if ((c = tb[IFACE_ATTR_NDPROXY_ROUTING]))
iface->learn_routes = blobmsg_get_bool(c);
void reload_services(struct interface *iface)
{
if (iface->ifflags & IFF_RUNNING) {
- syslog(LOG_DEBUG, "Enabling services with %s running", iface->ifname);
+ debug("Enabling services with %s running", iface->ifname);
router_setup_interface(iface, iface->ra != MODE_DISABLED);
dhcpv6_setup_interface(iface, iface->dhcpv6 != MODE_DISABLED);
ndp_setup_interface(iface, iface->ndp != MODE_DISABLED);
dhcpv4_setup_interface(iface, iface->dhcpv4 != MODE_DISABLED);
#endif
} else {
- syslog(LOG_DEBUG, "Disabling services with %s not running", iface->ifname);
+ debug("Disabling services with %s not running", iface->ifname);
router_setup_interface(iface, false);
dhcpv6_setup_interface(iface, false);
ndp_setup_interface(iface, false);
close(fd);
if (!json)
- syslog(LOG_ERR,
- "rfc9096: %s: json read error %s",
- iface->ifname,
- json_util_get_last_err());
+ error("rfc9096: %s: json read error %s",
+ iface->ifname,
+ json_util_get_last_err());
return json;
}
inet_pton(AF_INET6, pio_str, &pio->prefix);
pio->length = pio_len;
pio->lifetime = pio_lt;
- syslog(LOG_INFO,
- "rfc9096: %s: load %s/%u (%u)",
- iface->ifname,
- pio_str,
- pio_len,
- ra_pio_lifetime(pio, now));
+ info("rfc9096: %s: load %s/%u (%u)",
+ iface->ifname,
+ pio_str,
+ pio_len,
+ ra_pio_lifetime(pio, now));
iface->pio_cnt++;
}
O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC,
0644);
if (fd < 0) {
- syslog(LOG_ERR,
- "rfc9096: %s: error %m creating temporary json file",
- iface->ifname);
+ error("rfc9096: %s: error %m creating temporary json file",
+ iface->ifname);
return;
}
ret = json_object_to_fd(fd, json, JSON_C_TO_STRING_PLAIN);
if (ret) {
- syslog(LOG_ERR,
- "rfc9096: %s: json write error %s",
- iface->ifname,
- json_util_get_last_err());
+ error("rfc9096: %s: json write error %s",
+ iface->ifname,
+ json_util_get_last_err());
close(fd);
unlinkat(config.ra_piofolder_fd, tmp_piofile, 0);
return;
ret = fsync(fd);
if (ret) {
- syslog(LOG_ERR,
- "rfc9096: %s: error %m syncing %s",
- iface->ifname,
- tmp_piofile);
+ error("rfc9096: %s: error %m syncing %s",
+ iface->ifname,
+ tmp_piofile);
close(fd);
unlinkat(config.ra_piofolder_fd, tmp_piofile, 0);
return;
ret = close(fd);
if (ret) {
- syslog(LOG_ERR,
- "rfc9096: %s: error %m closing %s",
- iface->ifname,
- tmp_piofile);
+ error("rfc9096: %s: error %m closing %s",
+ iface->ifname,
+ tmp_piofile);
unlinkat(config.ra_piofolder_fd, tmp_piofile, 0);
return;
}
config.ra_piofolder_fd,
iface->ifname);
if (ret) {
- syslog(LOG_ERR,
- "rfc9096: %s: error %m renaming piofile: %s -> %s",
- iface->ifname,
- tmp_piofile,
- iface->ifname);
+ error("rfc9096: %s: error %m renaming piofile: %s -> %s",
+ iface->ifname,
+ tmp_piofile,
+ iface->ifname);
close(fd);
unlinkat(config.ra_piofolder_fd, tmp_piofile, 0);
return;
}
iface->pio_update = false;
- syslog(LOG_WARNING,
- "rfc9096: %s: piofile updated",
- iface->ifname);
+ warn("rfc9096: %s: piofile updated", iface->ifname);
}
void config_save_ra_pio(struct interface *iface)
close(config.ra_piofolder_fd);
config.ra_piofolder_fd = open(path, O_PATH | O_DIRECTORY | O_CLOEXEC);
if (config.ra_piofolder_fd < 0)
- syslog(LOG_ERR, "Unable to open piofolder '%s': %m", path);
+ error("Unable to open piofolder '%s': %m", path);
}
vlist_flush(&leases);
if (sendto(iface->dhcpv4_event.uloop.fd, &fr_msg, PACKET_SIZE(&fr_msg, cursor),
MSG_DONTWAIT, (struct sockaddr*)&dest, sizeof(dest)) < 0)
- syslog(LOG_ERR, "Failed to send %s to %s - %s: %m", dhcpv4_msg_to_string(msg),
- odhcpd_print_mac(a->hwaddr, sizeof(a->hwaddr)), inet_ntoa(dest.sin_addr));
+ error("Failed to send %s to %s - %s: %m", dhcpv4_msg_to_string(msg),
+ odhcpd_print_mac(a->hwaddr, sizeof(a->hwaddr)), inet_ntoa(dest.sin_addr));
else
- syslog(LOG_DEBUG, "Sent %s to %s - %s", dhcpv4_msg_to_string(msg),
- odhcpd_print_mac(a->hwaddr, sizeof(a->hwaddr)), inet_ntoa(dest.sin_addr));
+ debug("Sent %s to %s - %s", dhcpv4_msg_to_string(msg),
+ odhcpd_print_mac(a->hwaddr, sizeof(a->hwaddr)), inet_ntoa(dest.sin_addr));
}
static void dhcpv4_fr_stop(struct dhcp_assignment *a)
a, a->addr);
if (assigned)
- syslog(LOG_DEBUG, "Assigning static IP: %s",
- inet_ntop(AF_INET, &a->addr, ipv4_str, sizeof(ipv4_str)));
+ debug("Assigning static IP: %s",
+ inet_ntop(AF_INET, &a->addr, ipv4_str, sizeof(ipv4_str)));
return assigned;
}
a, raddr);
if (assigned) {
- syslog(LOG_DEBUG, "Assigning the IP the client asked for: %s",
- inet_ntop(AF_INET, &a->addr, ipv4_str, sizeof(ipv4_str)));
+ debug("Assigning the IP the client asked for: %s",
+ inet_ntop(AF_INET, &a->addr, ipv4_str, sizeof(ipv4_str)));
return true;
}
}
a, n_try);
if (assigned) {
- syslog(LOG_DEBUG, "Assigning mapped IP: %s (try %u of %u)",
- inet_ntop(AF_INET, &a->addr, ipv4_str, sizeof(ipv4_str)),
- i + 1, count);
+ debug("Assigning mapped IP: %s (try %u of %u)",
+ inet_ntop(AF_INET, &a->addr, ipv4_str, sizeof(ipv4_str)),
+ i + 1, count);
return true;
}
}
- syslog(LOG_NOTICE, "Can't assign any IP address -> address space is full");
+ notice("Can't assign any IP address -> address space is full");
return false;
}
/* Create new binding */
a = alloc_assignment(0);
if (!a) {
- syslog(LOG_WARNING, "Failed to alloc assignment on interface %s",
- iface->ifname);
+ warn("Failed to alloc assignment on interface %s",
+ iface->ifname);
return NULL;
}
memcpy(a->hwaddr, mac, sizeof(a->hwaddr));
req->op != DHCPV4_OP_BOOTREQUEST || req->hlen != ETH_ALEN)
return;
- syslog(LOG_DEBUG, "Got DHCPv4 request on %s", iface->name);
+ debug("Got DHCPv4 request on %s", iface->name);
if (!iface->dhcpv4_start_ip.s_addr && !iface->dhcpv4_end_ip.s_addr) {
- syslog(LOG_WARNING, "No DHCP range available on %s", iface->name);
+ warn("No DHCP range available on %s", iface->name);
return;
}
req->ciaddr.s_addr = INADDR_ANY;
}
- syslog(LOG_INFO, "Received %s from %s on %s", dhcpv4_msg_to_string(reqmsg),
- odhcpd_print_mac(req->chaddr, req->hlen), iface->name);
+ info("Received %s from %s on %s", dhcpv4_msg_to_string(reqmsg),
+ odhcpd_print_mac(req->chaddr, req->hlen), iface->name);
if (reqmsg == DHCPV4_MSG_DECLINE || reqmsg == DHCPV4_MSG_RELEASE)
return;
memcpy(arp.arp_dev, iface->ifname, sizeof(arp.arp_dev));
if (ioctl(sock, SIOCSARP, &arp) < 0)
- syslog(LOG_ERR, "ioctl(SIOCSARP): %m");
+ error("ioctl(SIOCSARP): %m");
}
}
if (send_reply(&reply, PACKET_SIZE(&reply, cursor),
(struct sockaddr*)&dest, sizeof(dest), opaque) < 0)
- syslog(LOG_ERR, "Failed to send %s to %s - %s: %m",
- dhcpv4_msg_to_string(msg),
- dest.sin_addr.s_addr == INADDR_BROADCAST ?
- "ff:ff:ff:ff:ff:ff": odhcpd_print_mac(req->chaddr, req->hlen),
- inet_ntoa(dest.sin_addr));
+ error("Failed to send %s to %s - %s: %m",
+ dhcpv4_msg_to_string(msg),
+ dest.sin_addr.s_addr == INADDR_BROADCAST ?
+ "ff:ff:ff:ff:ff:ff": odhcpd_print_mac(req->chaddr, req->hlen),
+ inet_ntoa(dest.sin_addr));
else
- syslog(LOG_DEBUG, "Sent %s to %s - %s",
- dhcpv4_msg_to_string(msg),
- dest.sin_addr.s_addr == INADDR_BROADCAST ?
- "ff:ff:ff:ff:ff:ff": odhcpd_print_mac(req->chaddr, req->hlen),
- inet_ntoa(dest.sin_addr));
+ debug("Sent %s to %s - %s",
+ dhcpv4_msg_to_string(msg),
+ dest.sin_addr.s_addr == INADDR_BROADCAST ?
+ "ff:ff:ff:ff:ff:ff": odhcpd_print_mac(req->chaddr, req->hlen),
+ inet_ntoa(dest.sin_addr));
if (msg == DHCPV4_MSG_ACK && a)
ubus_bcast_dhcp_event("dhcp.ack", req->chaddr,
if (iface->dhcpv4_start.s_addr & htonl(0xffff0000) ||
iface->dhcpv4_end.s_addr & htonl(0xffff0000) ||
ntohl(iface->dhcpv4_start.s_addr) > ntohl(iface->dhcpv4_end.s_addr)) {
- syslog(LOG_WARNING, "Invalid DHCP range for %s", iface->name);
+ warn("Invalid DHCP range for %s", iface->name);
return -1;
}
if (!iface->addr4_len) {
- syslog(LOG_WARNING, "No network(s) available on %s", iface->name);
+ warn("No network(s) available on %s", iface->name);
return -1;
}
/* Don't allocate IP range for subnets smaller than /28 */
if (iface->addr4[0].prefix > MAX_PREFIX_LEN) {
- syslog(LOG_WARNING, "Auto allocation of DHCP range fails on %s (prefix length must be < %d).", iface->name, MAX_PREFIX_LEN + 1);
+ warn("Auto allocation of DHCP range fails on %s (prefix length must be < %d).",
+ iface->name, MAX_PREFIX_LEN + 1);
return -1;
}
iface->dhcpv4_event.uloop.fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
if (iface->dhcpv4_event.uloop.fd < 0) {
- syslog(LOG_ERR, "socket(AF_INET): %m");
+ error("socket(AF_INET): %m");
ret = -1;
goto out;
}
/* Basic IPv4 configuration */
if (setsockopt(iface->dhcpv4_event.uloop.fd, SOL_SOCKET, SO_REUSEADDR,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(SO_REUSEADDR): %m");
+ error("setsockopt(SO_REUSEADDR): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->dhcpv4_event.uloop.fd, SOL_SOCKET, SO_BROADCAST,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(SO_BROADCAST): %m");
+ error("setsockopt(SO_BROADCAST): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->dhcpv4_event.uloop.fd, IPPROTO_IP, IP_PKTINFO,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IP_PKTINFO): %m");
+ error("setsockopt(IP_PKTINFO): %m");
ret = -1;
goto out;
}
val = IPTOS_PREC_INTERNETCONTROL;
if (setsockopt(iface->dhcpv4_event.uloop.fd, IPPROTO_IP, IP_TOS, &val,
sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IP_TOS): %m");
+ error("setsockopt(IP_TOS): %m");
ret = -1;
goto out;
}
val = IP_PMTUDISC_DONT;
if (setsockopt(iface->dhcpv4_event.uloop.fd, IPPROTO_IP, IP_MTU_DISCOVER,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IP_MTU_DISCOVER): %m");
+ error("setsockopt(IP_MTU_DISCOVER): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->dhcpv4_event.uloop.fd, SOL_SOCKET, SO_BINDTODEVICE,
iface->ifname, strlen(iface->ifname)) < 0) {
- syslog(LOG_ERR, "setsockopt(SO_BINDTODEVICE): %m");
+ error("setsockopt(SO_BINDTODEVICE): %m");
ret = -1;
goto out;
}
if (bind(iface->dhcpv4_event.uloop.fd, (struct sockaddr *)&bind_addr,
sizeof(bind_addr)) < 0) {
- syslog(LOG_ERR, "bind(): %m");
+ error("bind(): %m");
ret = -1;
goto out;
}
a = list_first_entry(&iface->dhcpv4_fr_ips, struct odhcpd_ref_ip, head);
if (netlink_setup_addr(&a->addr, iface->ifindex, false, true)) {
- syslog(LOG_WARNING, "Failed to add ip address on %s", iface->name);
+ warn("Failed to add ip address on %s", iface->name);
return;
}
border = alloc_assignment(0);
if (!border) {
- syslog(LOG_WARNING, "Failed to alloc border on %s", iface->name);
+ warn("Failed to alloc border on %s", iface->name);
return -1;
}
/* Filter Out Prefixes */
if (ADDR_MATCH_PIO_FILTER(&addrs[i], iface)) {
char addrbuf[INET6_ADDRSTRLEN];
- syslog(LOG_INFO, "Address %s filtered out on %s",
- inet_ntop(AF_INET6, &addrs[i].addr.in6, addrbuf, sizeof(addrbuf)),
- iface->name);
+ info("Address %s filtered out on %s",
+ inet_ntop(AF_INET6, &addrs[i].addr.in6, addrbuf, sizeof(addrbuf)),
+ iface->name);
continue;
}
/* Wait initial period of up to 250ms for immediate assignment */
if (poll(&pfd, 1, 250) < 0) {
- syslog(LOG_ERR, "poll(): %m");
+ error("poll(): %m");
return false;
}
/* Filter Out Prefixes */
if (ADDR_MATCH_PIO_FILTER(&addrs[i], iface)) {
char addrbuf[INET6_ADDRSTRLEN];
- syslog(LOG_INFO, "Address %s filtered out on %s",
- inet_ntop(AF_INET6, &addrs[i].addr.in6, addrbuf, sizeof(addrbuf)),
- iface->name);
+ info("Address %s filtered out on %s",
+ inet_ntop(AF_INET6, &addrs[i].addr.in6, addrbuf, sizeof(addrbuf)),
+ iface->name);
continue;
}
dhcpv6_ia_enum_addrs(iface, a, now, dhcpv6_log_ia_addr, &ctxt);
}
- syslog(LOG_INFO, "DHCPV6 %s %s from %s on %s: %s %s", type, (is_pd) ? "IA_PD" : "IA_NA",
- duidbuf, iface->name, status, leasebuf);
+ info("DHCPV6 %s %s from %s on %s: %s %s", type, (is_pd) ? "IA_PD" : "IA_NA",
+ duidbuf, iface->name, status, leasebuf);
}
static bool dhcpv6_ia_on_link(const struct dhcpv6_ia_hdr *ia, struct dhcp_assignment *a,
* 1/16 of our total address space.
*/
if (iface->dhcpv6_pd_min_len && reqlen < iface->dhcpv6_pd_min_len) {
- syslog(LOG_INFO, "clamping requested PD from %d to %d",
- reqlen, iface->dhcpv6_pd_min_len);
+ info("clamping requested PD from %d to %d", reqlen,
+ iface->dhcpv6_pd_min_len);
reqlen = iface->dhcpv6_pd_min_len;
}
} else if (is_na) {
else {
iov->iov_base = (void*)&(entry->bootfile_url);
iov->iov_len = 4 + ntohs(entry->bootfile_url.len);
- syslog(LOG_INFO, "Serve IPv6 PxE, arch = %d, url = %s", arch, entry->bootfile_url.payload);
+ info("Serve IPv6 PxE, arch = %d, url = %s", arch, entry->bootfile_url.payload);
}
}
}
if (count) {
- syslog(LOG_INFO, "IPv6 PxE URLs:\n");
+ info("IPv6 PxE URLs:\n");
- list_for_each_entry(entry, &ipv6_pxe_list, list) {
- syslog(LOG_INFO, " arch %04d = %s\n", entry->arch, entry->bootfile_url.payload);
- }
+ list_for_each_entry(entry, &ipv6_pxe_list, list)
+ info(" arch %04d = %s\n", entry->arch, entry->bootfile_url.payload);
if (ipv6_pxe_default)
- syslog(LOG_INFO, " Default = %s\n", ipv6_pxe_default->bootfile_url.payload);
+ info(" Default = %s\n", ipv6_pxe_default->bootfile_url.payload);
}
}
iface->dhcpv6_event.uloop.fd = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
if (iface->dhcpv6_event.uloop.fd < 0) {
- syslog(LOG_ERR, "socket(AF_INET6): %m");
+ error("socket(AF_INET6): %m");
ret = -1;
goto out;
}
/* Basic IPv6 configuration */
if (setsockopt(iface->dhcpv6_event.uloop.fd, SOL_SOCKET, SO_BINDTODEVICE,
iface->ifname, strlen(iface->ifname)) < 0) {
- syslog(LOG_ERR, "setsockopt(SO_BINDTODEVICE): %m");
+ error("setsockopt(SO_BINDTODEVICE): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->dhcpv6_event.uloop.fd, IPPROTO_IPV6, IPV6_V6ONLY,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_V6ONLY): %m");
+ error("setsockopt(IPV6_V6ONLY): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->dhcpv6_event.uloop.fd, SOL_SOCKET, SO_REUSEADDR,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(SO_REUSEADDR): %m");
+ error("setsockopt(SO_REUSEADDR): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->dhcpv6_event.uloop.fd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_RECVPKTINFO): %m");
+ error("setsockopt(IPV6_RECVPKTINFO): %m");
ret = -1;
goto out;
}
val = DHCPV6_HOP_COUNT_LIMIT;
if (setsockopt(iface->dhcpv6_event.uloop.fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_MULTICAST_HOPS): %m");
+ error("setsockopt(IPV6_MULTICAST_HOPS): %m");
ret = -1;
goto out;
}
val = 0;
if (setsockopt(iface->dhcpv6_event.uloop.fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_MULTICAST_LOOP): %m");
+ error("setsockopt(IPV6_MULTICAST_LOOP): %m");
ret = -1;
goto out;
}
if (bind(iface->dhcpv6_event.uloop.fd, (struct sockaddr*)&bind_addr,
sizeof(bind_addr)) < 0) {
- syslog(LOG_ERR, "bind(): %m");
+ error("bind(): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->dhcpv6_event.uloop.fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP,
&mreq, sizeof(mreq)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_ADD_MEMBERSHIP): %m");
+ error("setsockopt(IPV6_ADD_MEMBERSHIP): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->dhcpv6_event.uloop.fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP,
&mreq, sizeof(mreq)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_ADD_MEMBERSHIP): %m");
+ error("setsockopt(IPV6_ADD_MEMBERSHIP): %m");
ret = -1;
goto out;
}
struct dhcpv4_msg_data *reply = opaque;
if (len > reply->maxsize) {
- syslog(LOG_ERR, "4o6: reply too large, %zu > %zu", len, reply->maxsize);
+ error("4o6: reply too large, %zu > %zu", len, reply->maxsize);
reply->len = -1;
} else {
memcpy(reply->msg, buf, len);
}
if (!msgv4_data || msgv4_len == 0) {
- syslog(LOG_ERR, "4o6: missing DHCPv4 message option (%d)", DHCPV6_OPT_DHCPV4_MSG);
+ error("4o6: missing DHCPv4 message option (%d)", DHCPV6_OPT_DHCPV4_MSG);
return -1;
}
if (len < sizeof(*hdr))
return;
- syslog(LOG_DEBUG, "Got a DHCPv6-request on %s", iface->name);
+ debug("Got a DHCPv6-request on %s", iface->name);
/* Construct reply message */
struct __attribute__((packed)) {
msglen = dhcpv6_4o6_query(msg_opt->msg, sizeof(pdbuf) - sizeof(*msg_opt) + 1,
iface, addr, (const void *)hdr, opts_end);
if (msglen <= 0) {
- syslog(LOG_ERR, "4o6: query failed");
+ error("4o6: query failed");
return;
}
iov[IOV_DNR].iov_len + iov[IOV_BOOTFILE_URL].iov_len -
(4 + opts_end - opts));
- syslog(LOG_DEBUG, "Sending a DHCPv6-%s on %s", iov[IOV_NESTED].iov_len ? "relay-reply" : "reply", iface->name);
+ debug("Sending a DHCPv6-%s on %s", iov[IOV_NESTED].iov_len ? "relay-reply" : "reply", iface->name);
odhcpd_send(iface->dhcpv6_event.uloop.fd, addr, iov, ARRAY_SIZE(iov), iface);
}
/* Relay DHCPv6 reply from server to client */
struct dhcpv6_relay_header *h = (void*)data;
- syslog(LOG_DEBUG, "Got a DHCPv6-relay-reply");
+ debug("Got a DHCPv6-relay-reply");
if (len < sizeof(*h) || h->msg_type != DHCPV6_MSG_RELAY_REPL)
return;
struct iovec iov = {payload_data, payload_len};
- syslog(LOG_DEBUG, "Sending a DHCPv6-reply on %s", iface->name);
+ debug("Sending a DHCPv6-reply on %s", iface->name);
odhcpd_send(iface->dhcpv6_event.uloop.fd, &target, &iov, 1, iface);
}
h->msg_type == DHCPV6_MSG_ADVERTISE)
return; /* Invalid message types for client */
- syslog(LOG_DEBUG, "Got a DHCPv6-request on %s", iface->name);
+ debug("Got a DHCPv6-request on %s", iface->name);
if (h->msg_type == DHCPV6_MSG_RELAY_FORW) { /* handle relay-forward */
if (h->hop_count >= DHCPV6_HOP_COUNT_LIMIT)
ip = NULL;
}
- syslog(LOG_DEBUG, "Sending a DHCPv6-relay-forward on %s", c->name);
+ debug("Sending a DHCPv6-relay-forward on %s", c->name);
odhcpd_send(c->dhcpv6_event.uloop.fd, &s, iov, 2, c);
}
int ret = 0;
if (netlink_add_netevent_handler(&ndp_netevent_handler) < 0) {
- syslog(LOG_ERR, "Failed to add ndp netevent handler");
+ error("Failed to add ndp netevent handler");
ret = -1;
}
/* Open ICMPv6 socket */
iface->ndp_ping_fd = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6);
if (iface->ndp_ping_fd < 0) {
- syslog(LOG_ERR, "socket(AF_INET6): %m");
+ error("socket(AF_INET6): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->ndp_ping_fd, SOL_SOCKET, SO_BINDTODEVICE,
iface->ifname, strlen(iface->ifname)) < 0) {
- syslog(LOG_ERR, "setsockopt(SO_BINDTODEVICE): %m");
+ error("setsockopt(SO_BINDTODEVICE): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->ndp_ping_fd, IPPROTO_RAW, IPV6_CHECKSUM,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_CHECKSUM): %m");
+ error("setsockopt(IPV6_CHECKSUM): %m");
ret = -1;
goto out;
}
val = 255;
if (setsockopt(iface->ndp_ping_fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_MULTICAST_HOPS): %m");
+ error("setsockopt(IPV6_MULTICAST_HOPS): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->ndp_ping_fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_UNICAST_HOPS): %m");
+ error("setsockopt(IPV6_UNICAST_HOPS): %m");
ret = -1;
goto out;
}
ICMP6_FILTER_SETBLOCKALL(&filt);
if (setsockopt(iface->ndp_ping_fd, IPPROTO_ICMPV6, ICMP6_FILTER,
&filt, sizeof(filt)) < 0) {
- syslog(LOG_ERR, "setsockopt(ICMP6_FILTER): %m");
+ error("setsockopt(ICMP6_FILTER): %m");
ret = -1;
goto out;
}
iface->ndp_event.uloop.fd = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, htons(ETH_P_IPV6));
if (iface->ndp_event.uloop.fd < 0) {
- syslog(LOG_ERR, "socket(AF_PACKET): %m");
+ error("socket(AF_PACKET): %m");
ret = -1;
goto out;
}
int pktt = 1 << PACKET_MULTICAST;
if (setsockopt(iface->ndp_event.uloop.fd, SOL_PACKET, PACKET_RECV_TYPE,
&pktt, sizeof(pktt)) < 0) {
- syslog(LOG_ERR, "setsockopt(PACKET_RECV_TYPE): %m");
+ error("setsockopt(PACKET_RECV_TYPE): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->ndp_event.uloop.fd, SOL_SOCKET, SO_ATTACH_FILTER,
&bpf_prog, sizeof(bpf_prog))) {
- syslog(LOG_ERR, "setsockopt(SO_ATTACH_FILTER): %m");
+ error("setsockopt(SO_ATTACH_FILTER): %m");
ret = -1;
goto out;
}
ll.sll_protocol = htons(ETH_P_IPV6);
if (bind(iface->ndp_event.uloop.fd, (struct sockaddr*)&ll, sizeof(ll)) < 0) {
- syslog(LOG_ERR, "bind(): %m");
+ error("bind(): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->ndp_event.uloop.fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP,
&mreq, sizeof(mreq)) < 0) {
- syslog(LOG_ERR, "setsockopt(PACKET_ADD_MEMBERSHIP): %m");
+ error("setsockopt(PACKET_ADD_MEMBERSHIP): %m");
ret = -1;
goto out;
}
char ipbuf[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, addr, ipbuf, sizeof(ipbuf));
- syslog(LOG_DEBUG, "Pinging for %s on %s", ipbuf, iface->name);
+ debug("Pinging for %s on %s", ipbuf, iface->name);
netlink_setup_route(addr, 128, iface->ifindex, NULL, 128, true);
memcpy(&pbuf[sizeof(struct nd_neighbor_advert) + sizeof(struct nd_opt_hdr)], mac, 6);
inet_ntop(AF_INET6, to_addr, ipbuf, sizeof(ipbuf));
- syslog(LOG_DEBUG, "Answering NS to %s on %s", ipbuf, iface->ifname);
+ debug("Answering NS to %s on %s", ipbuf, iface->ifname);
/* Use link-local address as source for RFC 4861 compliance and macOS compatibility */
odhcpd_try_send_with_src(iface->ndp_ping_fd, &dest, &iov, 1, iface);
return; /* Invalid target */
inet_ntop(AF_INET6, &req->nd_ns_target, ipbuf, sizeof(ipbuf));
- syslog(LOG_DEBUG, "Got a NS for %s on %s", ipbuf, iface->name);
+ debug("Got a NS for %s on %s", ipbuf, iface->name);
odhcpd_get_mac(iface, mac);
is_self_sent = !memcmp(ll->sll_addr, mac, sizeof(mac));
char ipbuf[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, addr, ipbuf, sizeof(ipbuf));
- syslog(LOG_DEBUG, "%s about %s%s on %s",
- (add) ? "Learning" : "Forgetting",
- iface->learn_routes ? "proxy routing for " : "",
- ipbuf, iface->name);
+ debug("%s about %s%s on %s",
+ (add) ? "Learning" : "Forgetting",
+ iface->learn_routes ? "proxy routing for " : "",
+ ipbuf, iface->name);
if (iface->learn_routes)
netlink_setup_route(addr, 128, iface->ifindex, NULL, 1024, add);
if (netlink_setup_proxy_neigh(addr, c->ifindex, add)) {
if (add)
- syslog(LOG_ERR, "Failed to add proxy neighbour entry %s on %s",
- ipbuf, c->name);
+ error("Failed to add proxy neighbour entry %s on %s",
+ ipbuf, c->name);
} else
- syslog(LOG_DEBUG, "%s proxy neighbour entry %s on %s",
- add ? "Added" : "Deleted", ipbuf, c->name);
+ debug("%s proxy neighbour entry %s on %s",
+ add ? "Added" : "Deleted", ipbuf, c->name);
}
}
#include <errno.h>
#include <string.h>
-#include <syslog.h>
#include <linux/netlink.h>
#include <linux/if_addr.h>
{
rtnl_socket = create_socket(NETLINK_ROUTE);
if (!rtnl_socket) {
- syslog(LOG_ERR, "Unable to open nl socket: %m");
+ error("Unable to open nl socket: %m");
goto err;
}
rtnl_event.sock = create_socket(NETLINK_ROUTE);
if (!rtnl_event.sock) {
- syslog(LOG_ERR, "Unable to open nl event socket: %m");
+ error("Unable to open nl event socket: %m");
goto err;
}
return NL_SKIP;
}
- syslog(LOG_DEBUG, "Netlink %s %s on %s", add ? "newaddr" : "deladdr",
- buf, iface->name);
+ debug("Netlink %s %s on %s", add ? "newaddr" : "deladdr",
+ buf, iface->name);
event_info.iface = iface;
call_netevent_handler_list(add ? NETEV_ADDR6_ADD : NETEV_ADDR6_DEL,
if (iface->ifindex != (int)ifa->ifa_index)
continue;
- syslog(LOG_DEBUG, "Netlink %s %s on %s", add ? "newaddr" : "deladdr",
- buf, iface->name);
+ debug("Netlink %s %s on %s", add ? "newaddr" : "deladdr",
+ buf, iface->name);
event_info.iface = iface;
call_netevent_handler_list(add ? NETEV_ADDR_ADD : NETEV_ADDR_DEL,
if (iface->ifindex != ndm->ndm_ifindex)
continue;
- syslog(LOG_DEBUG, "Netlink %s %s on %s", true ? "newneigh" : "delneigh",
- buf, iface->name);
+ debug("Netlink %s %s on %s", true ? "newneigh" : "delneigh",
+ buf, iface->name);
event_info.iface = iface;
event_info.neigh.state = ndm->ndm_state;
#include <unistd.h>
#include <signal.h>
#include <stdbool.h>
-#include <syslog.h>
#include <alloca.h>
#include <inttypes.h>
uloop_init();
if (getuid() != 0) {
- syslog(LOG_ERR, "Must be run as root!");
+ error("Must be run as root!");
return 2;
}
ssize_t sent = sendmsg(socket, &msg, MSG_DONTWAIT);
if (sent < 0)
- syslog(LOG_ERR, "Failed to send to %s%%%s@%s (%m)",
- ipbuf, iface->name, iface->ifname);
+ error("Failed to send to %s%%%s@%s (%m)",
+ ipbuf, iface->name, iface->ifname);
else
- syslog(LOG_DEBUG, "Sent %zd bytes to %s%%%s@%s",
- sent, ipbuf, iface->name, iface->ifname);
+ debug("Sent %zd bytes to %s%%%s@%s",
+ sent, ipbuf, iface->name, iface->ifname);
return sent;
}
/* From netlink */
if (addr.nl.nl_family == AF_NETLINK) {
- syslog(LOG_DEBUG, "Received %zd Bytes from %s%%netlink", len,
- ipbuf);
+ debug("Received %zd Bytes from %s%%netlink", len, ipbuf);
e->handle_dgram(&addr, data_buf, len, NULL, dest);
return;
} else if (destiface != 0) {
if (iface->ifindex != destiface)
continue;
- syslog(LOG_DEBUG, "Received %zd Bytes from %s%%%s@%s", len,
- ipbuf, iface->name, iface->ifname);
+ debug("Received %zd Bytes from %s%%%s@%s", len,
+ ipbuf, iface->name, iface->ifname);
e->handle_dgram(&addr, data_buf, len, iface, dest);
}
extern struct vlist_tree leases;
extern struct config config;
+#define __iflog(lvl, fmt, ...) \
+ do { \
+ if (lvl <= config.log_level) \
+ syslog(lvl, fmt __VA_OPT__(, ) __VA_ARGS__); \
+ } while(0)
+
+#define debug(fmt, ...) __iflog(LOG_DEBUG, fmt __VA_OPT__(, ) __VA_ARGS__)
+#define info(fmt, ...) __iflog(LOG_INFO, fmt __VA_OPT__(, ) __VA_ARGS__)
+#define notice(fmt, ...) __iflog(LOG_NOTICE, fmt __VA_OPT__(, ) __VA_ARGS__)
+#define warn(fmt, ...) __iflog(LOG_WARNING, fmt __VA_OPT__(, ) __VA_ARGS__)
+#define error(fmt, ...) __iflog(LOG_ERR, fmt __VA_OPT__(, ) __VA_ARGS__)
+#define critical(fmt, ...) __iflog(LOG_CRIT, fmt __VA_OPT__(, ) __VA_ARGS__)
+#define alert(fmt, ...) __iflog(LOG_ALERT, fmt __VA_OPT__(, ) __VA_ARGS__)
+#define emergency(fmt, ...) __iflog(LOG_EMERG, fmt __VA_OPT__(, ) __VA_ARGS__)
+
+
struct odhcpd_event {
struct uloop_fd uloop;
void (*handle_dgram)(void *addr, void *data, size_t len,
int ret = 0;
if (!(fp_route = fopen("/proc/net/ipv6_route", "r"))) {
- syslog(LOG_ERR, "fopen(/proc/net/ipv6_route): %m");
+ error("fopen(/proc/net/ipv6_route): %m");
ret = -1;
goto out;
}
if (netlink_add_netevent_handler(&router_netevent_handler) < 0) {
- syslog(LOG_ERR, "Failed to add netevent handler");
+ error("Failed to add netevent handler");
ret = -1;
}
iface->router_event.uloop.fd = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC,
IPPROTO_ICMPV6);
if (iface->router_event.uloop.fd < 0) {
- syslog(LOG_ERR, "socket(AF_INET6): %m");
+ error("socket(AF_INET6): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->router_event.uloop.fd, SOL_SOCKET, SO_BINDTODEVICE,
iface->ifname, strlen(iface->ifname)) < 0) {
- syslog(LOG_ERR, "setsockopt(SO_BINDTODEVICE): %m");
+ error("setsockopt(SO_BINDTODEVICE): %m");
ret = -1;
goto out;
}
/* Let the kernel compute our checksums */
if (setsockopt(iface->router_event.uloop.fd, IPPROTO_RAW, IPV6_CHECKSUM,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_CHECKSUM): %m");
+ error("setsockopt(IPV6_CHECKSUM): %m");
ret = -1;
goto out;
}
val = 255;
if (setsockopt(iface->router_event.uloop.fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_MULTICAST_HOPS): %m");
+ error("setsockopt(IPV6_MULTICAST_HOPS): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->router_event.uloop.fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_UNICAST_HOPS): %m");
+ error("setsockopt(IPV6_UNICAST_HOPS): %m");
ret = -1;
goto out;
}
val = 1;
if (setsockopt(iface->router_event.uloop.fd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_RECVPKTINFO): %m");
+ error("setsockopt(IPV6_RECVPKTINFO): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->router_event.uloop.fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_RECVHOPLIMIT): %m");
+ error("setsockopt(IPV6_RECVHOPLIMIT): %m");
ret = -1;
goto out;
}
val = 0;
if (setsockopt(iface->router_event.uloop.fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
&val, sizeof(val)) < 0) {
- syslog(LOG_ERR, "setsockopt(IPV6_MULTICAST_LOOP): %m");
+ error("setsockopt(IPV6_MULTICAST_LOOP): %m");
ret = -1;
goto out;
}
ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filt);
if (setsockopt(iface->router_event.uloop.fd, IPPROTO_ICMPV6, ICMP6_FILTER,
&filt, sizeof(filt)) < 0) {
- syslog(LOG_ERR, "setsockopt(ICMP6_FILTER): %m");
+ error("setsockopt(ICMP6_FILTER): %m");
ret = -1;
goto out;
}
if (setsockopt(iface->router_event.uloop.fd, IPPROTO_IPV6,
IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
ret = -1;
- syslog(LOG_ERR, "setsockopt(IPV6_ADD_MEMBERSHIP): %m");
+ error("setsockopt(IPV6_ADD_MEMBERSHIP): %m");
goto out;
}
}
pio->lifetime = 0;
iface->pio_update = true;
- syslog(LOG_WARNING, "rfc9096: %s: renew %s/%u",
- iface->ifname,
- inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)),
- pio->length);
+ warn("rfc9096: %s: renew %s/%u",
+ iface->ifname,
+ inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)),
+ pio->length);
}
return;
pio->lifetime = 0;
iface->pio_update = true;
- syslog(LOG_INFO, "rfc9096: %s: add %s/%u",
- iface->ifname,
- inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)),
- pio->length);
+ info("rfc9096: %s: add %s/%u",
+ iface->ifname,
+ inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)),
+ pio->length);
}
static void router_clear_ra_pio(time_t now,
struct ra_pio *cur_pio = &iface->pios[i];
if (ra_pio_expired(cur_pio, now)) {
- syslog(LOG_INFO,
- "rfc9096: %s: clear %s/%u",
- iface->ifname,
- inet_ntop(AF_INET6, &cur_pio->prefix, ipv6_str, sizeof(ipv6_str)),
- cur_pio->length);
+ info("rfc9096: %s: clear %s/%u",
+ iface->ifname,
+ inet_ntop(AF_INET6, &cur_pio->prefix, ipv6_str, sizeof(ipv6_str)),
+ cur_pio->length);
if (i + 1 < iface->pio_cnt)
iface->pios[i] = iface->pios[iface->pio_cnt - 1];
pio->lifetime = now + iface->max_valid_lifetime;
iface->pio_update = true;
- syslog(LOG_WARNING, "rfc9096: %s: stale %s/%u",
- iface->ifname,
- inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)),
- pio->length);
+ warn("rfc9096: %s: stale %s/%u",
+ iface->ifname,
+ inet_ntop(AF_INET6, &pio->prefix, ipv6_str, sizeof(ipv6_str)),
+ pio->length);
}
/* Router Advert server mode */
uint32_t valid_lt = 0;
if (addr->prefix > 96 || (i < valid_addr_cnt && addr->valid_lt <= (uint32_t)now)) {
- syslog(LOG_INFO, "Address %s (prefix %d, valid-lifetime %u) not suitable as RA prefix on %s",
- inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)), addr->prefix,
- addr->valid_lt, iface->name);
+ info("Address %s (prefix %d, valid-lifetime %u) not suitable as RA prefix on %s",
+ inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)), addr->prefix,
+ addr->valid_lt, iface->name);
continue;
}
if (ADDR_MATCH_PIO_FILTER(addr, iface)) {
- syslog(LOG_INFO, "Address %s filtered out as RA prefix on %s",
- inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)),
- iface->name);
+ info("Address %s filtered out as RA prefix on %s",
+ inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)),
+ iface->name);
continue; /* PIO filtered out of this RA */
}
tmp = realloc(pfxs, sizeof(*pfxs) * (pfxs_cnt + 1));
if (!tmp) {
- syslog(LOG_ERR, "Realloc failed for RA prefix option on %s", iface->name);
+ error("Realloc failed for RA prefix option on %s", iface->name);
continue;
}
highest_found_lifetime = ra_lifetime;
if (!iface->have_link_local) {
- syslog(LOG_NOTICE, "Skip sending a RA on %s as no link local address is available", iface->name);
+ notice("Skip sending a RA on %s as no link local address is available", iface->name);
goto out;
}
} else {
adv.h.nd_ra_router_lifetime = 0;
- if (default_route) {
- syslog(LOG_WARNING, "A default route is present but there is no public prefix "
- "on %s thus we announce no default route by setting ra_lifetime to 0!", iface->name);
- } else {
- syslog(LOG_WARNING, "No default route present, setting ra_lifetime to 0!");
- }
+ if (default_route)
+ warn("A default route is present but there is no public prefix "
+ "on %s thus we announce no default route by setting ra_lifetime to 0!", iface->name);
+ else
+ warn("No default route present, setting ra_lifetime to 0!");
}
- syslog(LOG_DEBUG, "Using a RA lifetime of %d seconds on %s", ntohs(adv.h.nd_ra_router_lifetime), iface->name);
+ debug("Using a RA lifetime of %d seconds on %s", ntohs(adv.h.nd_ra_router_lifetime), iface->name);
/* DNS options */
if (iface->ra_dns) {
uint32_t valid_lt;
if (addr->dprefix >= 64 || addr->dprefix == 0 || addr->valid_lt <= (uint32_t)now) {
- syslog(LOG_INFO, "Address %s (dprefix %d, valid-lifetime %u) not suitable as RA route on %s",
- inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)),
- addr->dprefix, addr->valid_lt, iface->name);
+ info("Address %s (dprefix %d, valid-lifetime %u) not suitable as RA route on %s",
+ inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)),
+ addr->dprefix, addr->valid_lt, iface->name);
continue; /* Address not suitable */
}
if (ADDR_MATCH_PIO_FILTER(addr, iface)) {
- syslog(LOG_INFO, "Address %s filtered out as RA route on %s",
- inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)),
- iface->name);
+ info("Address %s filtered out as RA route on %s",
+ inet_ntop(AF_INET6, &addr->addr.in6, buf, sizeof(buf)),
+ iface->name);
continue; /* PIO filtered out of this RA */
}
tmp = realloc(routes, sizeof(*routes) * (routes_cnt + 1));
if (!tmp) {
- syslog(LOG_ERR, "Realloc failed for RA route option on %s", iface->name);
+ error("Realloc failed for RA route option on %s", iface->name);
continue;
}
else
inet_pton(AF_INET6, ALL_IPV6_NODES, &dest.sin6_addr);
- syslog(LOG_DEBUG, "Sending a RA on %s", iface->name);
+ debug("Sending a RA on %s", iface->name);
if (odhcpd_send(iface->router_event.uloop.fd, &dest, iov, ARRAY_SIZE(iov), iface) > 0) {
iface->ra_sent++;
inet_pton(AF_INET6, ALL_IPV6_ROUTERS, &all_routers.sin6_addr);
all_routers.sin6_scope_id = iface->ifindex;
- syslog(LOG_NOTICE, "Sending RS to %s", iface->name);
+ notice("Sending RS to %s", iface->name);
odhcpd_send(iface->router_event.uloop.fd, &all_routers, &iov, 1, iface);
}
}
}
- syslog(LOG_NOTICE, "Got a RA on %s", iface->name);
+ notice("Got a RA on %s", iface->name);
/* Indicate a proxy, however we don't follow the rest of RFC 4389 yet */
adv->nd_ra_flags_reserved |= ND_RA_FLAG_PROXY;
}
}
- syslog(LOG_NOTICE, "Forward a RA on %s", c->name);
+ notice("Forward a RA on %s", c->name);
odhcpd_send(c->router_event.uloop.fd, &all_nodes, &iov, 1, c);
}
-#include <syslog.h>
#include <libubus.h>
#include <libubox/uloop.h>
#include <netinet/in.h>
int ubus_init(void)
{
if (!(ubus = ubus_connect(NULL))) {
- syslog(LOG_ERR, "Unable to connect to ubus: %m");
+ error("Unable to connect to ubus: %m");
return -1;
}